<template>
	<view class="data-item">
		<view class="order-type">
			<view>设备巡检: <text>{{ value.apply_no }}</text></view>
			<!-- <view class="type red">待接单</view> -->
			<!-- <view class="type blue">已报修</view>
			<view class="type yellow">巡查异常</view> -->
		</view>
		<view class="order-info">
			<view class="info-item">
				<view class="key">设备信息：</view>{{ value.pd_inspecel_task.device_code }}-{{ value.pd_inspecel_task.device_name }}
			</view>
			<view class="info-item">
				<view class="key">巡检位置：</view>-
			</view>
			<view class="info-item">
				<view class="key">巡检时段：</view>{{ value.pd_inspecel_task.plan_start_time }} -
				{{ value.pd_inspecel_task.plan_end_time}}
			</view>
		</view>
		<view v-if="value.pd_inspecel_task.status === '10' && $util.getRights().pd_inspecel_task_dispatch"
			class="handle-btn">
			<view @click="acceptTask">派单</view>
		</view>
		<view v-else-if="value.pd_inspecel_task.status === '10' && $util.getRights().pd_inspecel_task_taking"
			class="handle-btn">
			<view @click="acceptTask">立即接单</view>
		</view>
		<view v-else-if="value.pd_inspecel_task.status === '20'" class="handle-btn">
			<view @click="rollbackTaking"
				v-if="$util.getRights().pd_inspecel_task_register || $util.getRights().pd_inspecel_task_dispatch">退回接单
			</view>
			<view @click="done" v-if="$util.getRights().pd_inspecel_task_register">立即处理</view>
			<view v-else @click="viewDetail">查看详情</view>
		</view>
		<!-- <view v-else-if="value.pd_inspecel_task.status === '30'" class="handle-btn">
			<view @click="check" v-if="$util.getRights().pd_inspecel_task_check">抽查</view>
			<view v-else @click="viewDetail">查看详情</view>
		</view> -->
		<view v-else-if="value.pd_inspecel_task.status === '90'" class="handle-btn">
			<view @click="done" v-if="$util.getRights().pd_inspecel_task_register">立即处理</view>
			<view v-else @click="viewDetail">查看详情</view>
		</view>
		<view v-else class="handle-btn">
			<view @click="viewDetail">查看详情</view>
		</view>
	</view>
</template>

<script>
export default {
	name: 'InspecelTask',
	props: {
		value: {
			type: Object,
			default: () => {
				return {}
			}
		}
	},
	data() {
		return {
		}
	},
	created() {
	},
	methods: {
		viewDetail(item) {
			console.warn("item: ", item)
			uni.navigateTo({
				url: '/pagesA/facility-patrol/facility-patrol-detail?inspeceId=' + this.value.pd_inspecel_task.inspece_id  //?isInList=true&data='+JSON.stringify(item) + "&eventName=" + eventName
			})
		},
		acceptTask() {
			uni.navigateTo({
				url: '/pagesA/facility-patrol/facility-patrol-accept?inspeceId=' + this.value.pd_inspecel_task.inspece_id//'/?repairId=' + this.value.pd_inspecel_task.repair_id //isInList=true&data='+JSON.stringify(this.value)
			})
		},
		done() {
			uni.navigateTo({
				url: '/pagesA/facility-patrol/facility-patrol-done?inspeceId=' + this.value.pd_inspecel_task.inspece_id //isInList=true&data='+JSON.stringify(this.value)
			})
		},
		// fix() {
		// 	uni.navigateTo({
		// 		url: '/pages/facility-patrol/facility-patrol-fix?inspeceId=' + this.value.pd_inspecel_task.inspece_id //isInList=true&data='+JSON.stringify(this.value)
		// 	})
		// },
		// check() {
		// 	uni.navigateTo({
		// 		url: '/pages/facility-patrol/facility-patrol-check?inspeceId=' + this.value.pd_inspecel_task.inspece_id //isInList=true&data='+JSON.stringify(this.value)
		// 	})
		// },
		rollbackTaking() {
			this.$util.confirm({
				content: "确定要退回当前接单？",
				confirmText: "退回"
			}).then(isConfirm => {
				if (isConfirm) {
					this.$util.post({
						url: "app/pdInspecelTask/rollbackTaking",
						data: {
							inspece_id: this.value.pd_inspecel_task.inspece_id
						}
					}).then(res => {
						console.log('22=========refreshPatrolTask')
						uni.$emit('refreshInspecelTask')
						uni.$emit('refreshHomeDataList')
					})
				}
			})
		},
	}
}
</script>

<style lang="scss" scoped>
.data-item {

	// display: flex;
	// margin-bottom: 30rpx;
	.order-type {
		display: flex;
		justify-content: space-between;
		font-size: 28rpx;
		color: #999999;

		>view:first-child {
			font-size: 32rpx;
			font-weight: bolder;
			color: #333333;
		}
	}

	.order-info {
		margin: 30rpx 0;

		.info-item {
			display: flex;
			font-size: 28rpx;
			color: #333333;
			line-height: 50rpx;

			.key {
				min-width: 150rpx;
				font-size: 28rpx;
				color: #999999;
			}

			.info-imgs {
				display: flex;
				flex-wrap: wrap;

				.img-item {
					width: 120rpx;
					height: 120rpx;
					margin: 2rpx 2rpx 0 0;
				}
			}
		}
	}

	.handle-btn {
		border-top: 1px solid #F5F5F5;
		height: 95rpx;
		margin-top: 20rpx;
		display: flex;

		>view {
			height: 95rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 32rpx;
			font-weight: bolder;
			color: #333333;
			flex: 1;
		}

		& :last-child {
			color: #0055FE;
		}
	}

	.target-info {
		flex: 1;
		display: flex;
		padding-bottom: 20rpx;

		.img {
			width: 260rpx;
			height: 295rpx;
			border-radius: 10rpx;
			margin-right: 20rpx;
		}

		.top {
			.name {
				font-size: 28rpx;
				font-weight: bolder;
				color: #333333;
			}

			.desc {
				font-size: 28rpx;
				color: #999999;
				margin-top: 10rpx;
			}
		}

		.fee {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 30rpx;

			.amount {
				font-size: 36rpx;
				color: #FF3737;
			}

			.common-btn {
				height: 60rpx;
				width: 160rpx;
				font-size: 28rpx;
				margin: 0;
			}
		}
	}
}

.type {
	font-size: 24rpx;
	font-weight: bolder;
	padding: 12rpx;
	border-radius: 4rpx;
}

.red {
	color: #FF3737;
	background-color: #FFEFEF;
}

.yellow {
	color: #FF972C;
	background-color: #FFF8EF;
}

.blue {
	color: #2C72FF;
	background-color: rgba($color: #A5C2FF, $alpha: .16);
}</style>
